package leedcode;

import java.util.*;

public class q128 {
    public static void main(String[] args) {
        Solution128 solution128 = new Solution128();
        int[] arr = new int[]{0, 3, 7, 2, 5, 8, 4, 6, 0, 1};
        System.out.println(solution128.longestConsecutive(arr));
    }
}


class Solution128 {
    public int longestConsecutive(int[] nums) {
        if (nums.length == 0){
            return 0;
        }
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));
        int n = 1;
        int tem = 1;
        for (int i = 0; i < nums.length; i++) {
            if (i + 1 < nums.length) {
                if (nums[i + 1] == nums[i] + 1) {
                    tem++;
                } else if (nums[i+1]==nums[i]) {

                } else {
                    if (tem > n) {
                        n = tem;
                    }
                    tem = 1;
                }
            } else {
                if (tem > n) {
                    n = tem;
                }
            }
        }
        return n;
    }
}
